<%@page import="com.kaishengit.dao.OrderItemDao"%>
<%@page import="com.kaishengit.entity.OrderItem"%>
<%@page import="com.kaishengit.entity.CarItem"%>
<%@page import="com.kaishengit.dao.OrderDao"%>
<%@page import="com.kaishengit.util.Const"%>
<%@page import="com.kaishengit.util.PKUtil"%>
<%@page import="com.kaishengit.util.DateUtil"%>
<%@page import="com.kaishengit.entity.Order"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="validate.jsp" %>
<%
	
	
	String name = request.getParameter("name");
	String address = request.getParameter("address");
	String tel = request.getParameter("tel");
	
	String orderId = PKUtil.getPk();
	
	Order order = new Order();
	order.setAddress(address);
	order.setCreateTime(DateUtil.getNow());
	order.setId(orderId);
	order.setName(name);
	order.setTel(tel);
	order.setUserid(user.getId());
	order.setState(Const.ORDER_STATE_1);
	
	OrderDao orderDao = new OrderDao();
	orderDao.save(order);
	
	List<CarItem> shopCar = (List<CarItem>)session.getAttribute("shopCar");
	
	OrderItemDao itemDao = new OrderItemDao();
	for(CarItem carItem : shopCar) {
		OrderItem orderItem = new OrderItem();
		orderItem.setNum(carItem.getNum());
		orderItem.setOrderId(orderId);
		orderItem.setProdId(carItem.getProd().getId());
		orderItem.setTotal(carItem.getPrice());
		
		itemDao.save(orderItem);
	}
	
	
	session.removeAttribute("shopCar");
	
	response.sendRedirect("suc.jsp");	
	
	

%>
